package application.dispatcher;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;

import org.dsrg.soenea.domain.command.CommandException;

import domain.command.InviteUserCommand;

public class InviteUserDispatcher extends Dispatcher
{

	public void execute() throws ServletException, IOException 
	{
		String requestMethod = this.myRequest.getMethod();
		boolean isPost =  "POST".equals(requestMethod);
		
		try 
		{
			new InviteUserCommand(myHelper, isPost).execute();			
			
			if( isAjax() ) 
			{
				// ajax call
				PrintWriter out = myResponse.getWriter();
				myResponse.setContentType("text/plain");
				out.println("A person has been invited!");
			} 
			else 
			{
				myHelper.setRequestAttribute("viewFile", "InviteUserTV");
				forward("/WEB-INF/JSP/template/template.jsp");
			}
			
			return;
			
		}
		catch (CommandException e)
		{
			forward("/WEB-INF/JSP/Errors.jsp");
			//e.printStackTrace();
		}
	}

}
